package org.lhq.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.lhq.entity.User;
import org.lhq.entity.UserFile;
import org.lhq.service.FileService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: admin-service
 * @description: 管理员管理文件
 * @author: Wang defa
 * @create: 2021-01-05 19:16
 */

@RestController
@Api(tags = "管理员管理用户文件")
@RequestMapping("fileManage")
public class AdminUserFileController {
    @Resource
    FileService fileService;

    @PostMapping("deleteTable")
    public void deleteById( Long id){
        fileService.deleteUserFileById(id);
    }
    @PostMapping("editTable")
    public void updateUserFile(UserFile userFile){
        fileService.updateUserById(userFile);
    }
    @PostMapping("userTable")
    public Page<UserFile> queryList(UserFile file, Long page, Long size){
        return this.fileService.getUserPage(file,size,page);
    }
    @PostMapping("batchDeleteTable")
    public Boolean batchDeleteTable(String batchId){
        List<String> idList = StrUtil.split(batchId,',');
        List<Long> userIds = idList.stream().map(Long::valueOf).collect(Collectors.toList());
        return fileService.batchDeleteTable(userIds);
    }
    @GetMapping("{id}")
    public UserFile getUserFileById(@PathVariable("id") Long id){
        return fileService.getUserFileById(id);
    }
    @GetMapping("user/{userId}")
    public List<UserFile> getUserFileListByUserId(@PathVariable("userId") Long userId){
    	return fileService.getUserFileListByUserId(userId);
	}

}
